<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="zh-cn">
<head>
    <!-- Bootstrap -->
    <include file="Include/css" />
    <title>商品</title>
    <!--编辑器--->
    <link type="text/css"  rel="stylesheet" href="__STATICS__/js/um/themes/default/css/umeditor.css" >
    <link href="__STATICS__/css/index.css" rel="stylesheet">
    <link href="__STATICS__/css/sweet-alert.css" rel="stylesheet">
    <link href="__STATICS__/css/daterangepicker.css" rel="stylesheet">
    <script type="text/javascript" src="__STATICS__/js/sweet-alert.min.js"></script>
     
</head>
<body>
<include file="Include/nav_top" />
<div class="container clearfix" id="left_menu_wraper" >
	<include  file="Include/menu_left" />
        <div id="right-content">
            <div id="right-content-inner">
                <ul class="breadcrumb">
                        <span>您的位置：</span>
                        <li><a href="index.php">首页</a> </li>
                        <li class="">商家管理</li>
                        <li class="">商家列表</li>
                        <li class="active">商品信息</li>
                </ul>
                
                <div class="back pull-right clearfix">
                    <a href="javascript:void(0);" class="btn btn-primary" id="save_msg" >提交信息</a>

                    <a class="btn btn-default" href="javascript:history.back();">
                        <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span> 后退
                    </a>  

                        
                </div>
                <!--tab-home start-->
                <div role="tabpanel">

                    <!-- Nav tabs -->
                    <ul class="nav nav-tabs clearfix" role="tablist">
                      <li role="presentation" class="active"><a href="#home" aria-controls="home" role="tab" data-toggle="tab">基本信息</a></li>
                      <li role="presentation"><a href="#profile" aria-controls="profile" role="tab" data-toggle="tab">详细描述</a></li>
                    </ul>

                    <!-- Tab panes start-->
                    <div class="tab-content">
                      <!--基本信息 开始-->
                      <div role="tabpanel" class="tab-pane active" id="home">
                          <div class="row clearfix">
                          
                          		 <div class="col-md-12 margin10" >
                                      <div class="col-md-2 text_right form_bar">
                                              上传图片：
                                      </div>
                                      <div class="col-md-4">
                                          <div class=" padding0 margin10">
                                              <div class="upload_wraper dash">
                                                  <div class="logo_wraper ">
                                                      <img id="pic"  src="{$imgDomain}{$showPic}" 
                                                           class="width100 img-rounded" alt="">
                                                      <input type="file" class="input_file" id="fileupload" name="file" value="" data-url="" multiple="">
                                                  </div>
													<input type="hidden" id="headImg" value="{$arr.headImg}" />
													<input type="hidden" id="thumb"  value="{$arr.thumb}" />
                                              </div>
                                          </div>
                                      </div>                                                                                             

                                  </div>
                          
                                <div class="col-md-12 margin10">
                                    <div class="col-md-2 text_right form_bar">
                                         商品名称：
                                    </div>
                                    <div class="col-md-4">
                                        <input id="goodsName" value="{$arr.goodsName}" type="text" class="form-control"/>
                                        <input id="goodsID" value="{$arr.goodsID}" type="hidden" />
                                        <input id="shopID" value="{$Think.request.shopID}" type="hidden" />
                                    </div>
                                    <div class="col-md-1 text_warning text_left form_bar">
                                                    *
                                    </div>
                                </div>
                            
                                <div class="col-md-12 margin10">
                                    <div class="col-md-2 text_right form_bar">
                                         商品编号：
                                    </div>
                                    <div class="col-md-4">
                                        <input id="goodsSn" value="{$arr.goodsSn}" type="text" class="form-control"/>
                                    </div>
                                    <div class="col-md-6 text_warning text_left form_bar">
                                          不填写则有系统随机分配
                                    </div>
                                </div>
                                <div class="col-md-12 margin10">
                                    <div class="col-md-2 text_right form_bar">
                                         排列顺序：
                                    </div>
                                    <div class="col-md-4">
                                        <input id="ind" value="{$arr.ind}" type="text" class="form-control"/>
                                    </div>
                                    <div class="col-md-6 text_warning text_left form_bar">
                                          
                                    </div>
                                </div>
                                <div class="col-md-12 margin10">
                                        <div class="col-md-2 text_right form_bar">
                                                商品类型：
                                        </div>
                                        <div class="col-md-4">
                                            <select id="catID" class="form-control">
                                                <volist name="catList" id="ct" >
                                                    <option value="{$ct.catID}" <eq name="ct['catID']" value="$arr['catID']" >selected</eq> >{$ct.catName}</option>
                                                </volist>
                                            </select>
                                        </div>
                                        <div class="col-md-1 text_warning text_left form_bar">
                                                *
                                        </div>
                                </div>
                              <div class="checkbox col-md-12">
                                  <div class="col-md-2 text_right form_bar">
                                  </div>
                                  <label>
                                      <input type="checkbox" id="checkboxTime" <eq name='arr.isTimeLimit' value='1'>checked</eq>> 是否限时抢购
                                  </label>
                              </div>
                              <div class="col-md-12 margin10 timeWrapper <neq name='arr.isTimeLimit' value='1'>hide</neq>">
                                  <div class="col-md-2 text_right form_bar">
                                      开始时间：
                                  </div>
                                  <div class="col-md-2">
                                      <input id="startTime" value="<notempty name='arr.limitStartTime'>{$arr.limitStartTime|date='Y:m:d H:i',###}</notempty>" type="text" class="form-control"/>
                                  </div>
                                  <div class="col-md-2 text_right form_bar">
                                      结束时间：
                                  </div>
                                  <div class="col-md-2">
                                      <input id="endTime" value="<notempty name='arr.limitEndTime'>{$arr.limitEndTime|date='Y:m:d H:i',###}</notempty>" type="text" class="form-control"/>
                                  </div>
                              </div>
                              
                                <div class="col-md-12 margin10">
                                        <div class="col-md-2 text_right form_bar">
                                                限制购买数量：
                                        </div>
                                        <div class="col-md-4">
                                            <input id="limitNum" value="{$arr.limitNum|default='0'}" type="text" class="form-control"/>
                                        </div>
                                        <div class=" text_warning text_left form_bar col-md-6">
                                                * -1 表示不限数量
                                        </div>
                                </div>
								<div class="col-md-12 margin10">
                                        <div class="col-md-2 text_right form_bar">
                                                月限制购买数量：
                                        </div>
                                        <div class="col-md-4">
                                            <input id="monthLimitNum" value="{$arr.monthLimitNum|default='0'}" type="text" class="form-control"/>
                                        </div>
                                        <div class=" text_warning text_left form_bar col-md-6">
                                                * -1 表示不限数量
                                        </div>
                                </div>
                                <div class="col-md-12 margin10">
                                        <div class="col-md-2 text_right form_bar">
                                                总库存：
                                        </div>
                                        <div class="col-md-4">
                                            <input id="num" value="{$arr.num|default='0'}" type="text" class="form-control"/>
                                        </div>
                                        <div class="col-md-6 text_warning text_left form_bar">
                                                * -1 表示不限库存
                                        </div>
                                </div>
                                <div class="col-md-12 margin10">
                                        <div class="col-md-2 text_right form_bar">
                                                剩余数量：
                                        </div>
                                        <div class="col-md-4">
                                             <input id="restNum" value="{$arr.restNum|default='0'}" type="text" class="form-control"/>
                                        </div>
                                        <div class="col-md-6 text_warning text_left form_bar">
                                                *
                                        </div>
                                </div>
                                <div class="col-md-12 margin10">
                                        <div class="col-md-2 text_right form_bar">
                                                已售数量：
                                        </div>
                                        <div class="col-md-4">
                                             <input id="saleNum" value="{$arr.saleNum|default='0'}" type="text" class="form-control"/>
                                        </div>
                                        <div class="col-md-6 text_warning text_left form_bar">
                                                *
                                        </div>
                                </div>
                                <div class="col-md-12 margin10">
                                    <div class="col-md-2 text_right form_bar">
                                            市场定价：
                                    </div>
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label class="sr-only" for="exampleInputAmount">默认定价 (in dollars)</label>
                                            <div class="input-group">
                                              <div class="input-group-addon">￥</div>
                                              <input type="text" class="form-control" id="marketPrice" 
                                                     value="{$arr.marketPrice}" placeholder="默认定价">
                                              <div class="input-group-addon">元</div>
                                            </div>
                                          </div>
                                    </div>
                                    <div class="col-md-1 text_warning text_left form_bar">
                                            *
                                    </div>
                                </div>
                                <div class="col-md-12 margin10">
                                    <div class="col-md-2 text_right form_bar">
                                            实际售价：
                                    </div>
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label class="sr-only" for="exampleInputAmount">实际售价 (in dollars)</label>
                                            <div class="input-group">
                                              <div class="input-group-addon">￥</div>
                                              <input type="text" class="form-control" id="goodsPrice" 
                                                     value="{$arr.goodsPrice}"  placeholder="实际售价">
                                              <div class="input-group-addon">元</div>
                                            </div>
                                          </div>
                                    </div>
                                    <div class="col-md-1 text_warning text_left form_bar">
                                            *
                                    </div>
                                </div>
                                
                                <div class="col-md-12 margin10">
                                        <div class="col-md-2 text_right form_bar">
                                                上架销售：
                                        </div>
                                        <div class="col-md-4">
                                           <!--<div class="col-md-12 margin10">-->
                                                <div class="btn-group clearfix" data-toggle="buttons">
                                                    <label class="btn btn-warning <eq name="arr['isSale']" value="1" >active</eq>" >
                                                        <input name="isSale" type="radio" id="allow_1" autocomplete="off" value="1"
                                                               <eq name="arr['isSale']" value="1" >checked</eq>
                                                               > 上架
                                                    </label>
                                                    <label class="btn btn-warning <eq name="arr['isSale']" value="0" >active</eq>">
                                                        <input name="isSale" type="radio" id="allow_0" autocomplete="off" value="0"
                                                               <eq name="arr['isSale']" value="0" >checked</eq>
                                                               > 下架
                                                    </label>
                                                </div>
                                            <!--</div>-->
                                        </div>
                                        <div class="col-md-1 text_warning text_left form_bar">
                                                *
                                        </div>
                                </div>

                    </div>
                      </div><!--基本信息结束-->
                      <!--详细信息 开始-->
                      <div role="tabpanel" class="tab-pane" id="profile">
                                 <textarea id="content" ></textarea>
                      </div><!--详细信息 结束-->
                      
                    </div><!--Tab panes over-->

                </div><!--tab-home over-->

            </div> <!--right-content-inner over-->
        </div> <!--right-content-->
        
</div><!--container over-->

<script id="editContent" type="template/edit-content">
	{$arr.desc}
</script>

<include file="Include/script" />
<script type="text/javascript" src="__STATICS__/js/jquery.ui.widget.js"></script>
<script type="text/javascript" src="__STATICS__/js//jquery.iframe-transport.js"></script>
<script type="text/javascript" src="__STATICS__/js/jquery.fileupload.js"></script>
<script type="text/javascript" src="__STATICS__/js/jquery-form.js"></script>
<script type="text/javascript" src="__STATICS__/js/upload_base.js"></script>
<script type="text/javascript" src="__STATICS__/js/moment.min.js"></script>
<script type="text/javascript" src="__STATICS__/js/daterangepicker.js"></script>

<!--编辑器-->
<script type="text/javascript" charset="utf-8" src="__STATICS__/js/um/umeditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__STATICS__/js/um/umeditor.min.js"></script>
<script type="text/javascript" src="__STATICS__/js/um/lang/zh-cn/zh-cn.js"></script>
<script>
    $(function(){
        $('#checkboxTime').change(function(){
            var self = $(this),
                $timeWrapper = $('.timeWrapper');
            if(self.is(':checked')){
                $timeWrapper.removeClass('hide').fadeIn();
            }
            else{
                $timeWrapper.fadeOut();
            }
        });
        $('#startTime,#endTime').daterangepicker({
                    "singleDatePicker": true,
                    "showDropdowns": true,
                    "showWeekNumbers": true,
                    "timePicker": true,
                    "timePicker24Hour": true,
                    "timePickerIncrement": 1,
                    "locale": {
                        format:'YYYY-MM-DD HH:mm',
                        "separator": " - ",
                        "applyLabel": "确定",
                        "cancelLabel": "取消",
                        "fromLabel": "From",
                        "toLabel": "To",
                        "customRangeLabel": "Custom",
                        "daysOfWeek": [
                            "日",
                            "一",
                            "二",
                            "三",
                            "四",
                            "五",
                            "六"
                        ],
                        "monthNames": [
                            "1月",
                            "2月",
                            "3月",
                            "4月",
                            "5月",
                            "6月",
                            "7月",
                            "8月",
                            "9月",
                            "10月",
                            "11月",
                            "12月"
                        ],
                        "firstDay": 1
            },
            "opens": "left",
            "drops": "down",
            "buttonClasses": "btn btn-sm",
            "applyClass": "btn-success",
            "cancelClass": "btn-default",
    }, function(start, end, label) {
    	//$(this).attr('data-id',(new Date(start._d)).getSeconds());
        });
    });
</script>
<script>
    /* 上传图片url */
    var headImgUrl = "{:U('CNEPAdmin/Upload/uploadImg/pathType/3')}";
    var myDom; // 当前的dom对象
    var img_url = "__STATICS__/images";
    var um = UM.getEditor('content',{
        initialFrameWidth:'90%'
    });  // 编辑器初始化
       
	$(document).ready(function () {
		
		
		
                
            /* 初始化编辑器里面的内容 */
            var content= $('#editContent').html();
            um.setContent(content);
              
            /* 上传主图 */
            upload_img_1(headImgUrl,'fileupload',onUpload);/*第一个参数：上传图片的路径,第二个参数：file_input标签id,第三个参数：回调函数*/
            
              /*上传主图之后回调*/
            function onUpload(rsp) {
                if(rsp.result > 0) {
                    $("#pic").attr("src",rsp.path);
                    $("#headImg").val(rsp.path);
                    $("#thumb").val(rsp.thumb);
                }else {
                    swal("上传失败;"+rsp.info,"","error");
                }
             }
             
             function checkGoodsValue() {
                 var rt = true;
                                        
                var goodsName = $.trim($("#goodsName").val());
                var headImg = $.trim($("#headImg").val()); // 主图
                var catID = $("#catID").val();
                var shopID = $("#shopID").val();
                var limitNum = $("#limitNum").val();
                var num = $("#num").val();
                var restNum = $("#restNum").val();
                var marketPrice = $("#marketPrice").val();
                var goodsPrice = $("#goodsPrice").val();
                var isSale =   $(":radio[name='isSale']:checked").val(); 
                var saleNum=$("#saleNum").val();
				var monthLimitNum = $("#monthLimitNum").val();
				
                
                if(goodsName == '' || goodsName == undefined)
                {   
                    rt = false;
                    $('#goodsName').focus();
                    swal('名称不能为空','','warning');
                }else if(catID <= 0 || catID == undefined)
                {   
                    rt = false;
                    $('#catID').focus();
                    swal('请选择商品类型','','warning');
                }else if(num == '' || parseInt(num) == NaN)
                {   
                    rt = false;
                    $('#num').focus();
                    swal('请输入正确的库存量','','warning');
                }else if(restNum == '' || parseInt(restNum) == NaN)
                {   
                    rt = false;
                    $('#restNum').focus();
                    swal('请输入正确的剩余库量','','warning');
                }else if(restNum == '' || parseInt(saleNum) == NaN)
                {   
                    rt = false;
                    $('#saleNum').focus();
                    swal('请输入正确的剩余库量','','warning');
                }else if(marketPrice == '' || parseFloat(marketPrice) == NaN)
                {   
                    rt = false;
                    $('#marketPrice').focus();
                    swal('请输入正确的默认价格','','warning');
                }else if(goodsPrice == '' || parseFloat(goodsPrice) == NaN)
                {   
                    rt = false;
                    $('#goodsPrice').focus();
                    swal('请输入正确的售价','','warning');
                }else if(isSale == undefined)
                {
                    rt = false;
                    $('#isSale').focus();
                    swal('请选择是否上架','','warning');
                }else if(headImg == '' || headImg == undefined)
                {   
                    rt = false;
                    $('#pic').focus();
                    swal('请上传商品主图','','warning');
                }else if(shopID <= 0 || shopID == undefined)
                {   
                    rt = false;
                    swal('请确认商店','','warning');
                }

                return rt;
                
             }

            $("#save_msg").on("click",function() {
                /* console.log(picJson); */
                
                // 校验数据
                if(!checkGoodsValue()) {
                    return false;
                }
                var limitNum =  $("#limitNum").val();
                if(limitNum <= 0 || isNaN(parseInt(limitNum))) {
                    limitNum = -1;
                }
				var monthLimitNum =  $("#monthLimitNum").val();
                if(monthLimitNum <= 0 || isNaN(parseInt(monthLimitNum))) {
                    monthLimitNum = -1;
                }
				
                var ajaxData = {};
                
                ajaxData.goodsName = $.trim($("#goodsName").val());
                ajaxData.desc = um.getContent(); // 详情
                ajaxData.headImg = $.trim($("#headImg").val()); // 主图
                ajaxData.thumb = $.trim($("#thumb").val()); // 主图缩略图
                ajaxData.catID = $("#catID").val();
                ajaxData.shopID = $("#shopID").val();
                ajaxData.ind = $("#ind").val();
                ajaxData.limitNum = limitNum;
				ajaxData.monthLimitNum = monthLimitNum;
				
                ajaxData.num = $("#num").val();
                ajaxData.restNum = $("#restNum").val();
                ajaxData.marketPrice = $("#marketPrice").val();
                ajaxData.goodsPrice = $("#goodsPrice").val();
                ajaxData.isSale =  $(":radio[name='isSale']:checked").val();
                ajaxData.saleNum=$("#saleNum").val();

                if($('#checkboxTime').is(':checked')){
                	ajaxData.isTimeLimit=1;
                    ajaxData.limitStartTime = $('#startTime').val().trim();
                    ajaxData.limitEndTime = $('#endTime').val().trim();
                }
                else{
                	ajaxData.isTimeLimit=0;
                }
                
                if($("#goodsID").val() > 0)
                    ajaxData.goodsID = $("#goodsID").val();

               console.log(ajaxData);
//               return;
                
                ajax_go_1(ajaxData,"{:U('CNEPAdmin/Goods/saveGoodsForMarket')}",onSave);
            });
            
	});
        
        function onSave(rsp) {
//            console.log(rsp);
//            return;
                if(rsp.result > 0) {
                    
                    if(rsp.type == 'add') {
                        $("#goodsID").val(rsp.goodsID);
                    }
                    
                    swal('保存成功','','success');
                    window.location.href = "{:U('CNEPAdmin/Goods/index')}?sShopID={$Think.request.shopID}&sGoodsSn={$Think.request.sGoodsSn}&sGoodsName={$Think.request.sGoodsName}&sCatID={$Think.request.sCatID}&sIsSale={$Think.request.sIsSale}&p={$Think.request.p}";
                } else {
                    swal('保存失败;'+rsp.desc,'','error');
                }
        }
        
        
        
</script>
</body>
</html>